<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎注册</title>
    <!-- <link href="css/register.css" rel="stylesheet"> -->
    <link rel="stylesheet" href="../../style/login/register.css">
    <script type="text/javascript" src="../../plugins/axios/axios.js"></script>
    <script type="text/javascript" src="../../plugins/vue/vue.js"></script>
    <script type="text/javascript" src="../../plugins/jQuery/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="../../plugins/layer-master/dist/layer.js"></script>

    <link rel="stylesheet" href="../../plugins/element-ui/index.css">
    <!-- 引入组件库 -->
    <script src="../../plugins/element-ui/index.js"></script>
</head>
<body>
<div id="app">
    <div class="form-div">
        <div class="reg-content">
            <h1>欢迎注册</h1>
            <span>已有帐号？</span> <a href="../login/login.html">登录</a>
        </div>
        <form id="reg-form" action="#" method="post">

            <table>
                <tr>
                    <td>用户名</td>
                    <td class="inputs">
                        <input name="username" type="text" id="username" v-model="username">
                    </td>
                </tr>

                <tr>
                    <td>密码</td>
                    <td class="inputs">
                        <input name="password" type="password" id="password" v-model="password">
                    </td>
                </tr>

                <tr>
                    <td>手机号</td>
                    <td class="inputs">
                        <input name="phone" type="text" id="phone" v-model="phone">
                    </td>
                </tr>
            </table>
            <div class="buttons">
                <input value="注 册" type="button" id="reg_btn" @click="registerFn">
            </div>
            <br class="clear">
        </form>
    </div>
</div>

<script>
    // 取消vue的开发模式
    Vue.config.productionTip = false;

    new Vue({
        el: "#app",
        data: {
            username: "",
            password: "",
            phone: "",
        },
        methods: {
            // 注册请求
            registerFn() {
                if (!((/^[0-9a-zA-Z_]+$/.test(this.username)) && (/^[0-9]+$/.test(this.password)))) {
                    return this.$message({
                        message: "请输入正确的用户名和密码(数字、字母、下划线组成)!",
                        type: 'error',
                        duration: 3000
                    });
                }

                if (!(/^1[3-9]\d{9}$/.test(this.phone))) {
                    return this.$message({
                        message: "请输入正确的手机号!",
                        type: 'error',
                        duration: 3000
                    });
                }

                axios({
                    resigter(){
                        let params=new URLSearchParams()
                        params.append('username',this.username)
                        params.append('password',this.password)
                        params.append('phone',this.phone)
                        axios({
                            method:'post',
                            url:'http://localhost:8004/user/login',
                            data:params
                        }).then(resp =>{
                            console.log(resp.data)
                            if (resp.data.success){
                                localStorage.setItem('front_token',resp.data.data)
                                location.href='../../index.html'
                            }else{
                                this.error='账号或者密码错误'
                            }
                        })
                        return false
                    }
                })
            }
        }
    })
</script>
</body>
</html>